<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('faq问题答案列表')" />
</head>
<body class="gray-bg">
<div class="row wrapper border-bottom white-bg page-heading">
    <div class="col-lg-10">
        <ol class="breadcrumb">
            <br/>
            <li>
                <a th:href="@{/front/home}">主页</a>
            </li>
            <li>
                <a>FAQ管理</a>
            </li>
            <li class="active">
                <strong>我的答案</strong>
            </li>
        </ol>
    </div>
</div>
     <div class="container-div">
        <div class="row">
            <div class="col-sm-12 search-collapse">
                <form id="formId">
                    <div class="select-list">
                        <ul>
                            <li>
                                <label>问题答案：</label>
                                <input type="text" name="answerAnswer"/>
                            </li>
                            <li class="select-time">
                                <label>采纳时间：</label>
                                <input type="text" class="time-input" id="startTime" placeholder="开始时间" name="params[beginAdoptTime]"/>
                                <span>-</span>
                                <input type="text" class="time-input" id="endTime" placeholder="结束时间" name="params[endAdoptTime]"/>
                            </li>
                            <li>
                                <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                                <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                            </li>
                        </ul>
                    </div>
                </form>
            </div>
            <div class="col-sm-12 select-table table-striped table-hover">
                <table id="bootstrap-table"></table>
            </div>
        </div>
    </div>
    <th:block th:include="include :: footer" />
    <script th:inline="javascript">
        var editFlag = [[${@permission.hasPermi('system:answer:myedit')}]];
        var removeFlag = [[${@permission.hasPermi('system:answer:remove')}]];
        var faqAnserAdoptStatusDatas = [[${@dict.getType('sys_faq_anser_adopt_status')}]];
        var detailFlag=[[${@permission.hasPermi('system:answer:detail')}]];
        var prefix = ctx + "system/answer";

        $(function() {
            var options = {
                url: prefix + "/myList",
                createUrl: prefix + "/add",
                updateUrl: prefix + "/edit?id={id}",
                removeUrl: prefix + "/remove",
                detailUrl: prefix + "/detail/{id}",
                showToggle:false,
                showHeader:true,
                showSearch:false,
                showRefresh:false,
                showColumns:false,
                striped:true,
                modalName: "faq问题答案",
                onPostBody: function() {
                    window.rowProps = undefined;
                    _table_rowspan("#bootstrap-table" , 1);
                    return true;
                },
                columns: [
                    {
                        title: "序号",
                        formatter: function (value, row, index) {
                            return $.table.serialNumber(index);
                        }
                    },
                {
                    field: 'id',
                    title: 'id',
                    visible: false
                },
                {
                    field: 'sysOaFaq',
                    title: '问题',
                    formatter: function(value, row, index) {
                        return $.table.tooltip(value.faqTitle);
                    }
                },
                {
                    field: 'answerAnswer',
                    title: '问题答案',
                    formatter: function(value, row, index) {
                        return $.table.tooltip(value);
                    }
                },
                {
                    field: 'answerFraction',
                    title: '答案分数'
                },

                {
                    field: 'isAdopt',
                    title: '是否采纳',
                    formatter: function(value, row, index) {
                        return $.table.selectDictLabel(faqAnserAdoptStatusDatas, value);
                    }
                },
            /*    {
                    field: 'answerLikes',
                    title: '问题点赞数'
                },
                {
                    field: 'answerRidicule',
                    title: '问题吐槽数'
                },*/
                {
                    field: 'adoptTime',
                    title: '采纳时间'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];

                        actions.push('<a class="btn btn-warning btn-xs ' + detailFlag + '" href="javascript:void(0)" onclick="$.operate.detail(\'' + row.id + '\')"><i class="fa fa-search"></i>详细</a> ');

                        if(row.isAdopt==0){
                            actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.id + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                            actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id + '\')"><i class="fa fa-remove"></i>删除</a>');
                        }

                        return actions.join('');
                    }
                }]
            };
            $.table.init(options);
        });


        //函数说明：合并指定表格（表格id为_t_id）指定列（列数为_t_colnum）的相同文本的相邻单元格
        //参数说明：_t_id 为需要进行合并单元格的表格的id。如在HTMl中指定表格 id="data" ，此参数应为 #data
        //参数说明：_t_colnum 为需要合并单元格的所在列。为数字，从最左边第一列为1开始算起。
        function _table_rowspan(_t_id, _t_colnum) {
            //声明合并数组
            var _t_merge_arr = [];
            //声明起始行、合并行数
            var _t_start_index = 0;
            var _t_merge_number = 0;
            //声明临时比较变量
            var _t_compare_value = '';
            //获取数据行数
            var _t_rows = null;
            if($(_t_id).length == 1){
                _t_rows = $(_t_id + " tr td:nth-child(" + _t_colnum + ")");
            } else if($(_t_id).length > 1){
                _t_rows = $(_t_id).eq($(_t_id).length - 1).find("tr td:nth-child(" + _t_colnum + ")");
            } else {
                return;
            }
            _t_rows.each(function(i) {
                var _t_temp_value = $(this).text();
                if (i==0) {
                    //首行不比较
                    _t_compare_value = _t_temp_value;
                    _t_merge_number ++;
                } else {
                    //对比本行数据和上行数据是否一样
                    if (_t_compare_value == _t_temp_value) {
                        _t_merge_number ++;
                        if(_t_merge_number > 1){
                            //声明合并行大于1的对象
                            var _t_merge_object = {index: _t_start_index,rowspan: _t_merge_number};
                            //取出合并数组最后一个对象
                            var _t_merge_arr_last_object = _t_merge_arr[_t_merge_arr.length - 1];
                            if (_t_merge_arr.length > 0) {
                                //根据起始下标看是否是同一合并
                                if (_t_merge_arr_last_object.index == _t_merge_object.index) {
                                    _t_merge_arr[_t_merge_arr.length - 1] = _t_merge_object;
                                } else {
                                    _t_merge_arr.push(_t_merge_object);
                                }
                            } else {
                                _t_merge_arr.push(_t_merge_object);
                            }
                        }
                    } else {
                        _t_merge_number = 1;
                        _t_start_index = i;
                        _t_compare_value = _t_temp_value;
                    }
                }
            });
            for (var i = 0; i < _t_merge_arr.length; i++) {
                var item = _t_merge_arr[i];
                var rowsnum = item.rowspan;
                for ( var j = 0; j < rowsnum-1; j++) {
                    $(_t_rows[item.index+j+1]).css('display','none');
                }
                $(_t_rows[item.index]).attr("rowSpan", item.rowspan);
            }
        }


    </script>
</body>
</html>